﻿//
// XN4SL - Xna Framework for Silverlight.
//
using System;

namespace Xn4Sl.Framework
{
    /// <summary>
    /// Snapshot of the game timing state expressed in values that can be used by
    /// variable-step (real time) or fixed-step (game time) games. 
    /// </summary>
    public class GameTime
    {
        /// <summary>
        /// Creates a new instance of Xn4Sl.Framework.GameTime.
        /// </summary>
        public GameTime() { }
        
        /// <summary>
        /// Creates a new instance of Xn4Sl.Framework.GameTime.
        /// </summary>
        /// <param name="totalRealTime">The amount of real time (wall clock) since the start of the game.</param>
        /// <param name="elapsedRealTime">The amount of elapsed real time (wall clock) since the last frame.</param>
        /// <param name="totalGameTime">The amount of game time since the start of the game.</param>
        /// <param name="elapsedGameTime">The amount of elapsed game time since the last update.</param>
        public GameTime(TimeSpan totalRealTime, TimeSpan elapsedRealTime, TimeSpan totalGameTime, TimeSpan elapsedGameTime) : this()
        {
            this.totalRealTime = totalRealTime;
            this.elapsedRealTime = elapsedRealTime;
            this.totalGameTime = totalGameTime;
            this.elapsedGameTime = elapsedGameTime;
        }

        /// <summary>
        /// Creates a new instance of Xn4Sl.Framework.GameTime.
        /// </summary>
        /// <param name="totalRealTime">The amount of real time (wall clock) since the start of the game.</param>
        /// <param name="elapsedRealTime">The amount of elapsed real time (wall clock) since the last frame.</param>
        /// <param name="totalGameTime">The amount of game time since the start of the game.</param>
        /// <param name="elapsedGameTime">The amount of elapsed game time since the last update.</param>
        /// <param name="isRunningSlowly">Whether the game is running multiple updates this frame.</param>
        public GameTime(TimeSpan totalRealTime, TimeSpan elapsedRealTime, 
                        TimeSpan totalGameTime, TimeSpan elapsedGameTime, bool isRunningSlowly) : 
                        this(totalRealTime, elapsedRealTime, totalGameTime, elapsedGameTime)
        {
            this.isRunningSlowly = isRunningSlowly;
        }

        /// <summary>
        /// The amount of elapsed game time since the last update.
        /// </summary>
        private TimeSpan elapsedGameTime = TimeSpan.Zero;
        public TimeSpan ElapsedGameTime
        {
            get
            {
                return this.elapsedGameTime;
            }
        }

        /// <summary>
        /// The amount of elapsed real time (wall clock) since the last frame.
        /// </summary>
        private TimeSpan elapsedRealTime = TimeSpan.Zero;
        public TimeSpan ElapsedRealTime
        {
            get
            {
                return this.elapsedGameTime;
            }
        }

        /// <summary>
        /// Gets a value indicating that the game loop is taking longer than its Game.TargetElapsedTime.
        /// In this case, the game loop can be considered to be running too slowly and should do something 
        /// to "catch up."
        /// </summary>
        private bool isRunningSlowly = false;
        public bool IsRunningSlowly
        {
            get
            {
                return this.isRunningSlowly;
            }
            set
            {
                this.isRunningSlowly = value;
            }
        }
        
        /// <summary>
        /// The amount of game time since the start of the game.
        /// </summary>
        private TimeSpan totalGameTime = TimeSpan.Zero;
        public TimeSpan TotalGameTime
        {
            get
            {
                return this.totalGameTime;
            }
        }

        /// <summary>
        /// The amount of real time (wall clock) since the start of the game.
        /// </summary>
        private TimeSpan totalRealTime = TimeSpan.Zero;
        public TimeSpan TotalRealTime
        {
            get
            {
                return this.totalRealTime;
            }
        }
    }
}
